﻿
Option Explicit On

Namespace Blog

    <CLSCompliant(True)> _
    Public Class PostCategory

        Inherits BlogSpark.Common.ObjectBase

#Region "Members"

        Private _PostCategoryId As Integer = 0
        Private _Title As String = String.Empty
        Private _Created As DateTime
        Private _Modified As DateTime

#End Region

#Region "Constructors"

        Public Sub New()
        End Sub

#End Region

#Region "Methods"

        Public Overrides Sub Fill(ByVal dr As DataRow)

            _PostCategoryId = dr(enumPostCategoryFields.PostCategoryID)
            Title = dr(enumPostCategoryFields.Title)
            Created = dr(enumPostCategoryFields.Created)
            Modified = dr(enumPostCategoryFields.Modified)

        End Sub

        Public Sub Save()

            If _PostCategoryId = 0 Then
                _PostCategoryId = BlogSpark.DataProvider.SPs.InsertPostCategory(BlogSpark.DataProvider.Data.ConnectionType, Title, Created, Modified)
            Else
                BlogSpark.DataProvider.SPs.UpdatePostCategory(BlogSpark.DataProvider.Data.ConnectionType, PostCategoryID, Title, Created, Modified)
            End If

        End Sub

        Public Sub Delete()

            BlogSpark.DataProvider.SPs.DeletePostCategory(BlogSpark.DataProvider.Data.ConnectionType, PostCategoryID)

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property PostCategoryID() As Integer
            Get
                Return _PostCategoryId
            End Get
        End Property

        Public Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        Public Property Created() As DateTime
            Get
                Return _Created
            End Get
            Set(ByVal value As DateTime)
                _Created = value
            End Set
        End Property

        Public Property Modified() As DateTime
            Get
                Return _Modified
            End Get
            Set(ByVal value As DateTime)
                _Modified = value
            End Set
        End Property

#End Region

#Region "Enums"

        Private Enum enumPostCategoryFields As Byte

            PostCategoryID = 0
            Title
            Created
            Modified

        End Enum

#End Region

    End Class

End Namespace

